package fun.hijklmn.magic.resource.common.utils;

import java.io.*;

/**
 * @Description
 * @Author fs
 * @Date 2021/5/26 14:34
 * @Version 0.0.1-SNAPSHOT
 **/
public class FileUtil {

    public static void transTo(InputStream inputStream, String targetFile) throws IOException {

        File outFile = new File(targetFile);

        if (outFile.exists()) {
            outFile.delete();
            outFile = new File(targetFile);
        }

        if (!outFile.exists()) {
            outFile.createNewFile();
        }

        FileOutputStream fileOutputStream = new FileOutputStream(new File(targetFile));

        byte[] b = new byte[2014];

        while (inputStream.read(b) != -1) {
            fileOutputStream.write(b);
        }

        fileOutputStream.flush();

        fileOutputStream.close();

    }

}
